<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网络订单收单列表</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/animate.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/style.min.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>网络订单收单列表</h5>
        </div>
        <div class="ibox-content">
            <div class="row row-lg">
                <div class="col-sm-12">
                    <div class="example-wrap">
                        <!-- start toolbar -->
                        <div class="col-sm-12">
                            <form class="form-horizontal" role="form" id="queryorderForm" autocomplete="off">
                                <div class="row">
                                 	<div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">订单号</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" placeholder="订单号"  id="orderNum" name="orderNum">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">发货人姓名</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" placeholder="寄件人姓名"  id="senderName" name="senderName">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">收货人姓名</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" placeholder="收件人姓名"  id="reciverName" name="reciverName">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">货车车牌号</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" placeholder="货车车牌号"  id="truckCarNum" name="truckCarNum">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">司机姓名</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control" placeholder="司机姓名"  id="driverName" name="driverName">
                                            </div>
                                        </div>
                                    </div>
                                    <!-- <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">支付方式</label>
                                            <div class="col-sm-8">
                                                <select id="orderPayWay" name="orderPayWay" class="form-control">
                                                    <option value="">-----选择支付方式-----</option>
                                                    <option value="0">-----微信-----</option>
                                                    <option value="1">-----支付宝-----</option>
                                                    <option value="3">-----银行卡-----</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div> -->
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">是否货到付款</label>
                                            <div class="col-sm-8">
                                                 <select id="orderFreightForward" name="orderFreightForward" class="form-control">
                                                    <option value="">-----请选择-----</option>
                                                    <option value="0">-----否-----</option>
                                                    <option value="1">-----是-----</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">代收货款</label>
                                            <div class="col-sm-8">
                                                 <select id="orderCod" name="orderCod" class="form-control">
                                                    <option value="">-----请选择-----</option>
                                                    <option value="1">-----否-----</option>
                                                    <option value="2">-----是-----</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">回单状态</label>
                                            <div class="col-sm-8">
                                                 <select id="orderReturnState" name="orderReturnState" class="form-control">
                                                    <option value="">选择回单状态</option>
                                                    <option value="0">-----未回单-----</option>
                                                    <option value="1">-----已回单-----</option>
                                                    <option value="-1">-----回单异常-----</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">开始时间</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control layer-date" placeholder="开始时间"  id="startTime" name="startTime">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                        <div class="form-group">
                                            <label class="col-sm-4 control-label">结束时间</label>
                                            <div class="col-sm-8">
                                                <input type="text" class="form-control layer-date" placeholder="结束时间"  id="endTime" name="endTime">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 col-lg-2">
                                    	<button type="button" class="btn btn-primary" id="queryOrderBtn">
                                            <span class="glyphicon glyphicon-search" aria-hidden="true"></span> 查询
                                        </button>
                                        <button type="button" class="btn btn-info" id="" onclick="location.reload();">
                                            <span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> 刷新
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <!-- end toolbar -->
                        <div class="example">
                            <table id="orderTab" class="table" data-click-to-select="true" data-mobile-responsive="true">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Panel Other -->
<script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${pageContext.request.contextPath}/js/content.min.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${pageContext.request.contextPath}/js/plugins/layer/layer.min.js"></script>
<script src="${pageContext.request.contextPath}/laydate/laydate.js"></script>
<script src="${pageContext.request.contextPath}/js/public/zywl-core.js"></script>

<script type="text/javascript">
var $table = $("#orderTab");
$(function () {
	//时间控件
	$.initDateScope('startTime','endTime',false);
    initTable();
    //获取公司名称
    var comnum = $("#comnumId").val();
    //如果公司不为nul和不为undefined，则加载下拉框的数据
    if(!comnum && typeof(comnum) != 'undefined'){
    	$.ajax({
            url: "../company/getCompanyIdAndName.htm",
            cache: false,
            type: "get",
            dataType: "json",
            success: function (result) {
                if (result.status == 0) {
                	var data = result.data;
                	addOptions(data, "#comnumId");
                    return;
                }
            }
        });
    }

    //查询事件
    $("#queryOrderBtn").click(function () {
        $table.bootstrapTable('refresh');	//使用post提交
    });
    
    //添加按钮事件
    $("#addBut").click(function(){
    	addEditOrderInfo(null,null);
    });
   
});

function initTable() {
    $table.bootstrapTable({
        dataType: "json",
         showColumns: true, 
        pagination: true, //分页
        striped: true,
        cache: false,	//是否使用缓存，默认是true
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "post",	//使用post提交
        queryParams: queryParams,
        url: '../webOrder/getComWebCollectOrderByPage.htm',
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
            {
                title: "序号",
                align: 'center',
                formatter:function(value,row,index){
                    return index + 1;
                }
            },
            {
                title: "订单号",
                field: "order.orderNum",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "寄件人姓名",
                field: "order.senderName",
                align: 'center', 
                valign: 'middle',
                formatter: function (value, row, index) {
                   if(row.order.senderName != null){
                       return '<a type="button" onclick="orderListEdit(\'' + row.order.senderId + '\',\'' + 1 + '\',\'' + row.order.orderNum + '\')">'+row.order.senderName+'</a>';
                   }
                   return '-';
                }
            },
            {
                title: "寄件人电话",
                field: "order.senderPhone",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "寄件人地址",
                field: "order.senderAddr",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "收件人姓名",
                field: "order.reciverName",
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                   if(row.order.reciverName != null){
                	   return '<a type="button" onclick="orderListEdit(\'' + row.order.reciverId + '\',\'' + 2 + '\',\'' + row.order.orderNum + '\')">'+row.order.reciverName+'</a>';
                   }
                   return '-';
                }
            },
            {
                title: "收件人电话",
                field: "order.reciverPhone",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "收件人地址",
                field: "order.reciverAddr",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "货物名称",
                field: "order.cargoName",
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                   if(row.order.cargoName != null){
                	   return '<a type="button" onclick="orderListEdit(\'' + row.order.cargoId + '\',\'' + 3 + '\',\'' + row.order.orderNum + '\')">'+row.order.cargoName+'</a>';
                   }
                   return '-';
                }
            },
            {
                title: "件数",
                field: "order.cargoAmount",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "仓库名",
                field: "order.storageName",
                align: 'center',
                valign: 'middle',
                visible:false,
                formatter: function (value, row, index) {
                   if(row.order.storageName != null){
                       return '<a type="button" onclick="orderListEdit(\'' + row.order.storageId + '\',\'' + 4 + '\',\'' + row.order.orderNum + '\')">'+row.order.storageName+'</a>';
                   }
                   return '-';
                }
            },
            {
                title: "仓储员",
                field: "order.stSaName",
                align: 'center',
                valign: 'middle',
               	visible:false
            },
            {
                title: "车辆车牌号",
                field: "truck.truckCarNum",
                align: 'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                   if(row.truck.truckCarNum != null){
                       return '<a type="button" onclick="orderListEdit(\'' + row.truck.truckId + '\',\'' + 5 + '\',\'' + row.truck.orderNum + '\')">'+row.truck.truckCarNum+'</a>';
                   }
                   return '-';
                }
            },
            {
                title: "司机姓名",
                field: "driver.driverName",
                align: 'center',
                valign: 'middle',
                visible:false,
                formatter: function (value, row, index) {
                   if(row.driver.driverName != null){
                       return '<a type="button" onclick="orderListEdit(\'' + row.driver.driverId + '\',\'' + 6 + '\',\'' + row.driver.orderNum + '\'">'+row.driver.driverName+'</a>';
                   }
                   return '-';
                }
            },
            {
                title: "司机电话",
                field: "driver.driverPhone",
                align: 'center',
                valign: 'middle',
                visible:false
            },
            {
                title: "支付状态",
                field: "order.orderManifestState",
                align: 'center',
                formatter: function(value, row, index){
                    var orderManifestState = "-";
                    if(row.order.orderManifestState == 0){
                        orderManifestState = '<span style="color:#ed5565;">未支付</span>';
                    }else if(row.order.comnumIsDelete == 1){
                        orderManifestState ='<span style="color:#23c6c8;">已支付</span>';
                    }else if(row.order.comnumIsDelete == 3){
                        orderManifestState ='<span style="color:#f8ac59;">支付异常</span>';
                    }
                    return orderManifestState;
                }
            },
            {
                title: "回单状态",
                field: "order.orderReturnState",
                align: 'center',
                visible: false,
                formatter: function(value, row, index){
                    var orderReturnState = "-";
                    if(row.order.orderReturnState == 0){
                        orderReturnState = '<span style="color:#ed5565;">未回单</span>';
                    }else if(row.order.orderReturnState == 1){
                        orderReturnState ='<span style="color:#23c6c8;">已回单</span>';
                    }else if(row.order.orderReturnState == -1){
                        orderReturnState ='<span style="color:#f8ac59;">回单异常</span>';
                    }
                    return orderReturnState;
                }
            },
            {
                title: "是否实名制",
                field: "order.senderIdCard",
                align: 'center',
                formatter: function(value, row, index){
            		var idCard = row.order.senderIdCard;
            		if(idCard && typeof(idCard) != 'undefined'){
            			idCard = '<span style="color:#ed5565;">是</span>';
            		}else{
            			idCard ='<span style="color:#23c6c8;">否</span>';
            		}
            		return idCard;
            	}
            },
            {
            	title: "货到付款",
                field: "order.orderFreightForward",
                align: 'center',
                visible: false,
                formatter: function(value, row, index){
                	var of = "-";
                    if(row.order.orderFreightForward == 0){
                    	of = '<span style="color:#ed5565;">否</span>';
                    }else if(row.order.orderFreightForward == 1){
                    	of ='<span style="color:#23c6c8;">是</span>';
                    }
                    return of;
            	}
            },
            {
            	title: "短运费用(元)",
            	field: "webCarriage",
            	align: "center",
            	valign: "middle"
            },
            {
            	title: "短运货车类型",
            	field: "webTruckType",
            	align: "center",
            	formatter: function(value, row, index){
            		var type = "-";
            		if(row.webTruckType == 1){
            			type = "中型车";
            		}else if(row.webTruckType == 2){
            			type = "小型车";
            		}else if(row.webTruckType == 3){
            			type = "微型车";
            		}
            		return type;
            	}
            },
            {
            	title: "网络订单状态",
            	field: "webOrderState",
            	align: "center",
            	formatter: function(value, row, index){
            		var state = "-";
            		if(row.webOrderState == 0){
            			state = "未支付";
            		}else if(row.webOrderState == 1){
            			state = "已支付";
            		}else if(row.webOrderState == 2){
            			state = "物流接单";
            		}else if(row.webOrderState == 3){
            			state = "货运接单";
            		}else if(row.webOrderState == 4){
            			state = "货运结单";
            		}else if(row.webOrderState == -1){
            			state = "订单异常";
            		}
            		return state;
            	}
            },
            {
            	title: "长途运费(元)",
                field: "order.carriage",
                align: 'center',
                valign: 'middle',
                visible: false,
            },
            {
            	title: "代收金额(元)",
                field: "order.orderCod",
                align: 'center',
                valign: 'middle',
                visible: false,
            },
            {
            	title: "附加费用(元)",
                field: "order.orderAddedFee",
                align: 'center',
                valign: 'middle',
                visible: false,
            },
            {
            	title: "备注",
                field: "order.orderNotes",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "订单生成时间",
                field: "webInsDate",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "操作",
                align: 'center',
                formatter: function (value, row, index) {
                    var d = '';
                    var e = '';
                	if(row.webOrderState == 1){
                    	e = '<button class="btn btn-xs btn-info" type="button" onclick="webCollectOrder(\'' + row.order.orderNum + '\')"><i class="fa fa-edit"></i>接单</button>';
                	}else if(row.webOrderState == 2 || row.webOrderState == 3) {
                		e = '<button class="btn btn-xs btn-info" type="button"><i class="fa fa-info-circle"></i>已接单</button>';
                	}
                    if(row.orderIsDelete == 0){
                    	d = '<button class="btn btn-xs btn-danger" type="button" onclick="delOrderInfo(\'' + row.orderId + '\',\'' + row.order.orderNum + '\')"><i class="fa fa-trash-o"></i>取消</button>';
                    }
                    return e + d;
                }
            }
        ],
        onClickRow: function(row, $element, field){	//当点击某一行时，该行背景颜色改变
        	var trObj = $($element[0]);
        	var dataIndex = trObj.attr('data-index');
        	$("tr[data-index != '" + dataIndex + "']").removeAttr('style');
        	trObj.attr('style', 'background: #B4EEB4');
        }
    });
}

//分页参数，条件查询时的参数
function queryParams(queryParamsType){
	var temp = {
		"limit": queryParamsType.limit,
		"offset": queryParamsType.offset,
		"order.orderNum": $.trim($('#orderNum').val()),
		"order.senderName": $.trim($('#senderName').val()),
		"order.reciverName": $.trim($('#reciverName').val()),
		"truck.truckCarNum": $.trim($('#truckCarNum').val()),
		"driver.driverName": $.trim($('#driverName').val()),
		"order.orderReturnState": $.trim($('#orderReturnState').val()),
		"startTime": $.trim($('#startTime').val()),
		"endTime": $.trim($('#endTime').val()),
		"order.orderFreightForward": $.trim($('#orderFreightForward').val()),
		"order.orderCod": $.trim($('#orderCod').val())
	};
	return temp;
}


//网络收单
function webCollectOrder(webOrderNum){
    $.ajax({
        url: "../webOrder/webCollectOrder.htm",
        cache: false,
        type: "get",
        dataType: "json",
        data: {'webOrderNum': webOrderNum},
        success: function (result) {
            if (result.status == 0) {
                layer.msg(result.message, {icon: 1});
                $table.bootstrapTable('refresh', {url: '../webOrder/getComWebCollectOrderByPage.htm'});
                return;
            }else{
            	layer.msg(result.message, {icon: 2});
            }
        }
    });
}

//取消订单
function webCancelOrder(id, orderNum) {
    layer.confirm('确定要删除编号【'+ sn +'】的订单吗？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        $.ajax({
            url: "../order/delOrderInfo.htm",
            cache: false,
            type: "post",
            dataType: "json",
            data: {'orderNum': orderNum},
            success: function (result) {
                if (result.status == 0) {
                    layer.msg(result.message, {icon: 1});
                    $table.bootstrapTable('refresh', {url: '../webOrder/getComWebCollectOrderByPage.htm'});
                    return;
                }else{
                	layer.msg(result.message, {icon: 2});
                }
            }
        });
    }, function () {});
}

//订单详情
function orderListEdit(id, type, orderNum){
	var title = '';
	switch (type) {
	case '1':
		title = '寄件人详情'
		break;
	case '2':
		title = '收件人详情'
		break;
	case '3':
		title = '货物详情'
		break;
	case '4':
		title = '仓库详情'
		break;
	case '5':
		title = '车辆详情'
		break;
	case '6':
		title = '司机详情'
		break;
	case '7':
		title = '公司详情'
		break;
	default:
		break;
	}
    layer.open({
        type: 2,
        title: '订单号【' + orderNum + '】—' + title,
        maxmin: false,
        shadeClose: false, //点击遮罩关闭层
        area : ['500px' , '750px'],
        content: '../weborder/webCollectOrder_details.htm?id=' + id + '&type=' + type,
        success: function(layero, index){
        }
    });
}

//comnum的下拉列表  追加到option中
function addOptions(data, selectId){
	for(var i=0; i<data.length; i++){
		$(selectId).append('<option value="' + data[i].comnumId + '">' + data[i].comnumName + '</option>');
	}
}
</script>
</body>
</html>
